<?
include("config.php");
if(isset($_GET['what'])) $what=$_GET['what']; else $what="";
if(isset($_GET['cat'])) $cat=$_GET['cat']; else $cat="";

if($what=='popular'){

	$query1 = "SELECT SQL_CACHE * FROM ".$table." WHERE viewcount > 0 AND enabled = 1 AND chanworking = 1 ORDER BY viewcount DESC LIMIT 10";
	$result1 = mysql_query($query1,$dbz) or die (mysql_error());
	while ($record1 = mysql_fetch_array($result1) ) { $records1[] = $record1; }

	foreach ($records1 as $rec){
		echo "<a title=\"".$rec['discription']."\" onclick=\"Play('".$rec['tvid']."')\" href=\"Javascript:Play('".$rec['tvid']."')\">".$rec['channel']."</a><br />";
	}

}elseif($what=='recent'){

	$query1 = "SELECT SQL_CACHE * FROM ".$table." WHERE enabled = 1 AND chanworking = 1 ORDER BY dateviewed DESC LIMIT 10";
	$result1 = mysql_query($query1,$dbz) or die (mysql_error());
	while ($record1 = mysql_fetch_array($result1) ) { $records1[] = $record1; }

	foreach ($records1 as $rec){
		echo "<a title=\"".$rec['discription']."\" onclick=\"Play('".$rec['tvid']."')\" href=\"Javascript:Play('".$rec['tvid']."')\">".$rec['channel']."</a><br />";
	}

}elseif($what=='categories'){
}elseif($what=='countries'){

}elseif($what=='catchanns'){

	$query1 = "SELECT SQL_CACHE * FROM ".$table." WHERE categories LIKE '%".str_replace("_"," ",$cat)."%' AND enabled = 1 AND chanworking = 1 ORDER BY channel";
	$result1 = mysql_query($query1,$dbz) or die (mysql_error());
	while ($record1 = mysql_fetch_array($result1) ) { $records1[] = $record1; }

	if(!empty($records1)){
		foreach ($records1 as $rec){
			if($rec['player']=="nw") $nw=" (external)"; else $nw="";
			echo "<li onclick=\"Play('".$rec['tvid']."')\" title=\"".$rec['discription']."\">".$rec['channel'].$nw."</li>";
		}
	}

}elseif($what=='cntrychanns'){

	$query1 = "SELECT SQL_CACHE * FROM ".$table." WHERE country = '".str_replace("_"," ",$cat)."' AND enabled = 1 AND chanworking = 1 ORDER BY channel";
	$result1 = mysql_query($query1,$dbz) or die (mysql_error());
	while ($record1 = mysql_fetch_array($result1) ) { $records1[] = $record1; }

	if(!empty($records1)){
		foreach ($records1 as $rec){
			if($rec['player']=="nw") $nw=" (external)"; else $nw="";
			echo "<li onclick=\"Play('".$rec['tvid']."')\" title=\"".$rec['discription']."\">".$rec['channel'].$nw."</li>";
		}
	}

}elseif($what=='play'){

	$query1 = "SELECT SQL_CACHE * FROM ".$table." WHERE tvid = '".$cat."' LIMIT 1";
	$result1 = mysql_query($query1,$dbz) or die (mysql_error());
	while ($record1 = mysql_fetch_array($result1) ) { $records1[] = $record1; }

	$rec=$records1[0];

	$st=$rec['streamurl'];
	$fv=$rec['flashvars'];

	if($rec['player']!="nw") echo "<div align='left' style='padding: 4px; color:#FFFFFF;'><b>".$rec['channel']."</b></div>";

	if($rec['chanworking']==0){
		if($rec['player']!="nw") echo "<p style='font-size:20px; color:#FFFFFF;'><br><br><br><br><b>".$rec['channel']."</b><br>This Channel is currently not working.<br><br><b>Please try again later.</b></p>";
	}elseif($rec['player']=="sl"){
		mysql_query("UPDATE ".$table." SET viewcount = viewcount + 1, dateviewed = NOW() WHERE tvid='".$cat."'", $dbz) or die(mysql_error());
?>
<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="490" height="320">
  <param name="source" value="<?=$st ?>"/>
  <param name="minRuntimeVersion" value="5.1.10401.0" />
  <param name="onerror" value="onSilverlightError" />
  <param name="background" value="black" />
  <a href="http://go.microsoft.com/fwlink/?LinkID=124807" style="text-decoration: none;"><img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/></a>
  <param name="initParams" value="<?=$fv ?>" />
</object>
<?
	}elseif($rec['player']=="wm" || $rec['player']=="wmp"){
		mysql_query("UPDATE ".$table." SET viewcount = viewcount + 1, dateviewed = NOW() WHERE tvid='".$cat."'", $dbz) or die(mysql_error());
?>
<object classid="clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#version=5,1,52,701" standby="Please wait..." type="application/x-ms-wmp" width="490" height="320">
	 <param name="filename" value="<?=$st ?>">
     <param name="animationatstart" value="true">
     <param name="transparentatstart" value="true">
     <param name="autostart" value="true">
     <param name="showcontrols" value="true">
     <param name="ShowStatusBar" value="false">
     <param name="windowlessvideo" value="true">
     <embed src="<?=$st ?>" type="application/x-mplayer2"  autostart="true" showcontrols="true" showstatusbar="0" bgcolor="white" width="490" height="320">
</object>
<?
	}elseif($rec['player']=="fp"){
		mysql_query("UPDATE ".$table." SET viewcount = viewcount + 1, dateviewed = NOW() WHERE tvid='".$cat."'", $dbz) or die(mysql_error());
?>
<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="490" height="320">
  <PARAM NAME=movie VALUE="<?=$st ?>">
  <PARAM NAME=quality VALUE=high>
  <PARAM NAME=bgcolor VALUE=#000000>
  <PARAM NAME=allowfullscreen VALUE="true">
  <PARAM NAME=allowscriptaccess VALUE="always">
  <PARAM NAME=flashvars VALUE="<?=$fv ?>">
  <EMBED
 data="<?=$st ?>"
 src="<?=$st ?>"
 width="490"
 height="320"
 allowscriptaccess="always"
 allowfullscreen="true"
 flashvars="<?=$fv ?>"
> </EMBED>
</OBJECT>
<?

	}elseif($rec['player']=="yt"){
		mysql_query("UPDATE ".$table." SET viewcount = viewcount + 1, dateviewed = NOW() WHERE tvid='".$cat."'", $dbz) or die(mysql_error());
		echo str_replace('width="560"','width="490"',$rec['embedcode']);
	}elseif($rec['player']=="iframe"){
		mysql_query("UPDATE ".$table." SET viewcount = viewcount + 1, dateviewed = NOW() WHERE tvid='".$cat."'", $dbz) or die(mysql_error());
?>
<iframe src="<?=$st ?>" frameborder="0" scrolling="no" width="490" height="320"></iframe>
<?
	}elseif($rec['player']=="nw"){
		echo "NW|".$rec['channel']."|".$rec['streamurl']."|FIN";
	}	
if($rec['player']!="nw"){

echo "<div align='center' style='padding: 4px; color:#FFFFFF;'><b>Please allow some time for the stream to start playing</b></div>";
		$eml="mailto:".$email;
		$eml.="?Subject=Channel Not Working";
		$eml.="&Body=Channel Info:".urlencode("\n\n")."Channel ID: ".$rec['tvid'].urlencode("\n")."Channel: ".$rec['channel'].urlencode("\n")."Category: ".$rec['category'].urlencode("\n")."Discription: ".$rec['discription'];

		echo "<a align=\"center\" href=\"".$eml."\" style='color:#99FFFF; font-weight:bold'>Channel Not Working? Report It</a>";
}
}
?>